import java.util.*;
public class Practice3{
    //https://ac.nowcoder.com/acm/contest/72369
    //c题, 考察回文子串, 需要复习, 每天重新复习一下
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] ss = sc.next().toCharArray();
        int n = ss.length;
        int max = 101;
        for(int i = 0;i < n;i++){
            int left = i - 1;
            int right = i + 1;
            while(left >= 0 && right < n && ss[left] == ss[right]){
                left--;
                right++;
            }

            //aabbbbbb
            if(right - left - 1 > 1){
                max = Math.min(max,right - left - 1);
            }
            left = i;
            right = i + 1;
            while(left >= 0 && right < n && ss[left] == ss[right]){
                left--;
                right++;
            }
            if(right - left - 1 > 1){
                max = Math.min(max,right - left - 1);
            }
        }
        System.out.print(max == 1? -1 : max);
    }
}